
using System;
using Gnome;
using Gdk;

namespace DiaCanvas
{
	public class Rectangulo:Figura
	{
	
		protected Gdk.Point _point;
		
		private int _height;
		private int _width;
		
		private Gnome.CanvasRect _fig;
		
		override protected Gnome.CanvasShape Shape { get { return this._fig; }}
		
		public Rectangulo(Gdk.Point p, int w, int h, Gnome.Canvas c):base(c)
		{
			Console.WriteLine("Hijo");
			this._point.X = p.X;
			this._point.Y = p.Y;

			this._height = h;
			this._width = w;
			
			this._fig = new Gnome.CanvasRect(this._canvas.Root());
			
			CalculateControlPoints();
		}
		
		override protected void Resize(Object obj, EventButton ev)
		{
			double dx = ev.X - this._oldPoint.X;
			double dy = ev.Y - this._oldPoint.Y;
			
					
		}
		
		protected override void CalculateControlPoints()
		{
			int z = 10;
		
			this._points = new Gdk.Point[4];
			this._points.SetValue( new Point( this._point.X + this._width / 2 ,this._point.Y + z ),0);
			this._points.SetValue( new Point(this._point.X + z ,this._point.Y + this._height/2 ),1);
			this._points.SetValue( new Point(this._point.X + this._width / 2 ,this._point.Y + this._height - z),2);
			this._points.SetValue( new Point(this._point.X + this._width - z ,this._point.Y + this._height/2 ),3);
		}
		
		override public string toString()
		{
			return "Este es un rectangulo";
		}
		
		public override FiguraType Type { get { return FiguraType.Rectangulo; } }
		
		override public void draw()
		{
			this._fig.X1 = this._point.X;
			this._fig.Y1 = this._point.Y;
			this._fig.X2 = this._point.X+this._width;
			this._fig.Y2 = this._point.Y+this._height;
			
			
			this._fig.CanvasEvent += new Gnome.CanvasEventHandler(CanvasEvent);
						
			this._fig.OutlineColor = this._color.ForeGround;
			this._fig.FillColor = this._color.BackGround;
       		this._fig.WidthPixels = 1;
       		this._fig.Show();
       		
       		DrawControlPoints();
		}
		
		override protected void DrawControlPoints()
		{
		
			for ( int i = 0 ; i < this._points.Length ; i++)
			{	
				int radio = 2;
				Gnome.CanvasEllipse e =  new Gnome.CanvasEllipse(this._canvas.Root()); 
				this._p.Add(e);
				e.X1 = ((Gdk.Point)this._points[i]).X-radio;
				e.Y1 = ((Gdk.Point)this._points[i]).Y-radio;
				e.X2 = ((Gdk.Point)this._points[i]).X+radio;
				e.Y2 = ((Gdk.Point)this._points[i]).Y+radio;
				
				e.OutlineColor = "#fff";//this.BackColor;
				e.FillColor = "#fff";//this.BackColor;
				
				e.WidthPixels = 5;//this.BorderSize;

				e.CanvasEvent += new Gnome.CanvasEventHandler(CanvasEvent);
				
				e.Hide();
			}
			
		}
		

		/*
		public void CanvasEvent(object obj, Gnome.CanvasEventArgs args)
		{
			
			EventButton ev = new EventButton (args.Event.Handle);
			switch (ev.Type) 
			{
				case EventType.MotionNotify:
					if ( this._bDrag )
					{
						this.Move(ev);
					}
					break;
					
				case EventType.EnterNotify:
					MouseEnter(obj,args);
					break;
	
					
				case EventType.LeaveNotify:
					MouseLeave(obj,args);
					break;
	
				case EventType.DragEnter:
					
					break;
					
				case EventType.ButtonPress:
					if ( this._bIn )
					{
						this._bDrag = true;
						this._oldPoint.X = (int)ev.X;
						this._oldPoint.Y = (int)ev.Y;
					}
					break;
					
				case EventType.ButtonRelease:
					if ( this._bDrag )
					{
						this.Move(ev);
					}
					this._bDrag = false;
					break;
			}
			
		}*/
		
		protected override void ChangeColor()
		{
			
			//this._fig .OutLineColor = this._foreColor;
		}
		
	}
}
